package com.crm.controller.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.amqp.core.Message;
/**
 * @author zjd
 * @Title:
 * @Description:
 * @date 2021/4/1610:06
 */
@Component
public class ExchangeConsumer {

    /**
     * 监听绑定了direct交换机的的消息队列
     */
    @RabbitHandler
    @RabbitListener(queues = "LONGLY_WOLF_ORDER_QUEUE")
    public void directConsumer(String msg){
        System.out.println("direct交换机收到消息：" + msg);
    }

    /**
     * 监听绑定了topic交换机的的消息队列
     */
    @RabbitHandler
    @RabbitListener(queues = "LONGLY_WOLF_USER_QUEUE")
    public void topicConsumer(String msg){
        System.out.println("topic交换机收到消息：" + msg);
    }

    /**
     * 监听绑定了fanout交换机的的消息队列
     */
    @RabbitHandler
    @RabbitListener(queues = "LONGLY_WOLF_PRODUCT_QUEUE")
    public void fanoutConsumer(String msg){
        System.out.println("fanout交换机收到消息：" + msg);
    }

    /**
     * 监听ttl消息队列
     */
    @RabbitHandler
    @RabbitListener(queues = "LONGLY_WOLF_TTL_QUEUE")
    public void ttlConsumer(Message message){
        System.out.println("ttl队列收到消息：" + new String(message.getBody()));
        System.out.println("ttl队列收到消息：" + JSONObject.toJSONString(message.getMessageProperties()));
    }

    /**
     * 监听dead ttl消息队列
     */
    @RabbitHandler
//    @RabbitListener(queues = "LONGLY_WOLF_DEAD_LETTER_QUEUE")
    public void deadTtlConsumer(Message message){
        System.out.println("dead ttl队列收到消息：" + new String(message.getBody()));
        System.out.println("dead ttl队列收到消息：" + JSONObject.toJSONString(message.getMessageProperties()));
    }
}

